package com.example.owner.lettery1.other;

import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.Drawable;

import com.example.owner.lettery1.R;



/**
 * Created by Administrator on 2016/10/29.
 */
public abstract class ItemCreator {
    private int mCount = -1;
    private int[] mWeights;
    private Context mContext;
    private Drawable mVerticalDivider;
    private int mHorizontalDividerColor;

    public ItemCreator(Context context) {
        mContext = context;
        mVerticalDivider = mContext.getResources().getDrawable(R.drawable.sx_form_bg);
        mHorizontalDividerColor = Color.parseColor("#EBEBEB");
    }

    public ItemCreator(Context context, int... weights) {
        this(context);
        setCount(weights.length);
        setWeights(weights);
    }


    public Context getContext() {
        return mContext;
    }

    /**
     * 设置每一行的字段数
     *
     * @param count
     */
    public void setCount(int count) {
        mCount = count;
    }

    public int getCount() {
        return mCount;
    }

    /**
     * 设置每个字段宽度的权重,如果没有设置,默认所有字段权重为1
     *
     * @param weights
     */
    public void setWeights(int... weights) {
        setCount(weights.length);
        mWeights = weights;
    }

    /**
     * 获取指定位置的权重,如果为空则返回1.
     *
     * @param position
     * @return
     */
    public int getWeight(int position) {
        return getWeights()[position];
    }

    public int[] getWeights() {
        if (mWeights == null) {
            mWeights = new int[mCount];
            for (int i = 0; i < mCount; i++) {
                mWeights[i] = 1;
            }
        }
        return mWeights;
    }

    public void setVerticalDivider(Drawable drawable) {
        mVerticalDivider = drawable;
    }

    public Drawable getVerticalDivider() {
        return mVerticalDivider;
    }

    public void setHorizontalDividerColor(int color) {
        mHorizontalDividerColor = color;
    }

    public int getHorizontalDividerColor() {
        return mHorizontalDividerColor;
    }

    public abstract TextTableViewHolder createItem(String... texts);

}
